<template>
  <div class="menu">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <el-button @click="$router.push({ name: 'menu-create' })">添加广告位</el-button>
      </div>
      <el-table
        :data="adSpaceList"
        style="width: 100%">
        <el-table-column
          prop="spaceKey"
          label="spaceKey"
          min-width="150"
        >
        </el-table-column>
        <el-table-column
          prop="name"
          label="广告位名称"
          min-width="150">
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="创建时间"
          min-width="150">
        </el-table-column>
        <el-table-column
          prop="updateTime"
          label="更新时间"
          min-width="150">
        </el-table-column>
        <el-table-column
          label="操作"
          min-width="150">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handleEdit(scope.row)">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script lang="ts">
import Vue from 'vue'
// import { getAdList, changeState } from '@/services/advert'
import { getAdSpaceList } from '@/services/advert-space'

export default Vue.extend({
  name: 'AdvertIndex',
  data () {
    return {
      filterParams: {
        currentPage: 1,
        pageSize: 10
      },
      // adList: [],
      adSpaceList: []
    }
  },
  created () {
    this.loadAllAdPlaces()
  },
  // computed: {
  //   adSpace () {
  //     return (ad: any) => {
  //       const space = this.adSpaceList.find((adSpace: any) => adSpace.id === ad.spaceId)
  //       return space ? (space as any).name : ''
  //     }
  //   }
  // },
  methods: {
    async loadAllAdPlaces () {
      const { data } = await getAdSpaceList()
      this.adSpaceList = data.content
      console.log(data)
    }
    // handleEdit (item: any) {
    //   this.$router.push({
    //     name: 'advert-edit',
    //     params: {
    //       id: item.id
    //     }
    //   })
    // },
    // async onStateChange (ad: any) {
    //   ad.isStatusLoading = true
    //   await changeState({
    //     id: ad.id,
    //     status: ad.status === 0 ? 1 : 0
    //   })
    //   this.$message.success(`${ad.status === 0 ? '下架' : '上架'}成功`)
    //   ad.isStatusLoading = false
    // }

  }
})
</script>

<style lang="scss" scoped></style>
